package zredis

import (
	"github.com/gomodule/redigo/redis"
)

// HSet HSet
func HSet(tableName, key, value any) error {
	conn, err := GetConn()
	if err != nil {
		return err
	}
	defer autoClose(conn)

	_, err = conn.Do("HSET", tableName, key, value)
	return err
}

// HGet HGet
func HGet(tableName, key any) any {
	conn, err := GetConn()
	if err != nil {
		return nil
	}
	defer autoClose(conn)

	reply, err := conn.Do("HGET", tableName, key)
	if err != nil {
		return nil
	}
	return reply
}

// HGetInt64 HGetInt64
func HGetInt64(tableName, key any) int64 {
	conn, err := GetConn()
	if err != nil {
		return 0
	}
	defer autoClose(conn)

	reply, err := redis.Int64(conn.Do("HGET", tableName, key))
	if err == nil {
		return reply
	}
	return 0
}
